package org.example.mybatis.extend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.mybatis.extend.bean.Animal;
import org.example.mybatis.extend.service.AnimalService;
import com.bianmaba.spring.mvc.config.annotation.EntityParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("animal")
public class AnimalController {
    @Autowired
    private AnimalService animalService;

    @RequestMapping("get_by_id")
    public ResponseEntity getById(final int id) {
        return ResponseEntity.ok(animalService.getById(id));
    }

    @RequestMapping("add")
    public ResponseEntity add(@EntityParam final Animal animal) {
        return ResponseEntity.ok(animalService.add(animal));
    }

    @RequestMapping("extend_metnod")
    public ResponseEntity extendMethod(final int id) {
        return ResponseEntity.ok(animalService.extendMethod(id));
    }

    @RequestMapping("query")
    public ResponseEntity query(final String name, Page page) {
        return ResponseEntity.ok(animalService.query(name, page));
    }

}
